import { Pipe, PipeTransform } from '@angular/core';

/**
 * Generated class for the DateformatPipe pipe.
 *
 * See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
 * Angular Pipes.
 */
@Pipe({
  name: 'dateformat',
})
export class DateformatPipe implements PipeTransform {
    /**
     * Takes a value and makes it lowercase.
     */
    transform(value: string, ...args) {
        let date = new Date(value);
        if (args.length > 0) {
            if (args[0] == 'date') {
                return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            } else if (args[0] == 'time') {
                return date.getHours() + ':' + date.getMinutes();
            }
        } else {
            return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes();
        }
    }
}
